package com.fortune.controller;

import com.fortune.base.BaseAPIExcution;
import com.fortune.base.BaseController;
import com.fortune.dto.excution.COrderExcution;
import com.fortune.dto.excution.ClientUserExcution;
import com.fortune.dto.in.cOrder.COrderProductDto;
import com.fortune.dto.in.cOrder.COrderProductEditDto;
import com.fortune.dto.in.cOrder.PurchaseGiftDto;
import com.fortune.dto.in.clientOrder.CCClientOrderEditDto;
import com.fortune.dto.in.clientOrder.DOrderSubmitDto;
import com.fortune.dto.in.clientOrder.ListDto;
import com.fortune.entity.HistoryOrder;
import com.fortune.entity.Order;
import com.fortune.enums.COrderEnum;
import com.fortune.enums.ClientUserEnum;
import com.fortune.exception.db.DeleteInnerErrorException;
import com.fortune.exception.db.InsertInnerErrorException;
import com.fortune.exception.db.UpdateInnerErrorException;
import com.fortune.service.COrderService;
import com.fortune.service.ClientUserService;
import com.fortune.service.HistoryOrderService;
import com.fortune.util.UUIDUtil;
import com.fortune.vo.cOrder.CorderSubmit;
import com.fortune.vo.clientOrder.OrderDetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@Api(value = "wechat/history/order", description = "客户历史订单相关", tags = {"微信小程序（业务员）：客户历史订单管理"})
@RestController
@RequestMapping("wechat/history/order")
public class HistoryOrderController extends BaseController{

	@Autowired
	private HistoryOrderService historyOrderService;

	@ApiOperation(value = "历史订单列表", nickname = "clientHistoryOrderList", notes = "", tags={ "@郭阳" })
	@ApiImplicitParams({
			@ApiImplicitParam(name="Authorization", value="登录返回的token值",paramType="header",dataType="String",required = true),
			@ApiImplicitParam(name="clientId", value="客户id",paramType="query",dataType="string"),
	})
	@GetMapping(value = "list",
			produces = { MediaType.APPLICATION_JSON_VALUE })
	public BaseAPIExcution<HistoryOrder> clientOrderList(ListDto listDto, @Validated @NotBlank(message="客户id不能为空") String clientId) {
		String did = getDId();
		List<Order> clientOrderList = historyOrderService.selectClientList(listDto,did,clientId);
		Integer count = historyOrderService.acount(did, clientId);
		HistoryOrder historyOrder = new HistoryOrder();
		historyOrder.setCount(count);
		historyOrder.setOrders(clientOrderList);
		return new ClientUserExcution<HistoryOrder>(historyOrder, ClientUserEnum.FIND_SUCCESS);
	}

}
